package org.subside.filter;


import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 过滤器，对于全局访问接口进行操作，鉴权，加解密等
 */
@Component
@WebFilter(urlPatterns = "/*", filterName = "encodeFilter")
@Order(2)
public class EncodeFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
            ServletException {
        // TODO 业务逻辑  加密 解密  修改 body
        BodyReaderHttpServletRequestWrapper bodyReaderHttpServletRequestWrapper = null;
        try {
            bodyReaderHttpServletRequestWrapper = new BodyReaderHttpServletRequestWrapper((HttpServletRequest) request);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        if(true){
            chain.doFilter(bodyReaderHttpServletRequestWrapper, response);
        }

    }

    @Override
    public void destroy() {

    }
}


